<template>
  <div class="course-content">
    <!-- 轮播图 -->
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item
        v-for="item in activeAdList"
        :key="item.id">
        <img :src="item.img">
      </van-swipe-item>
    </van-swipe>
    <!-- 列表项 -->
    <course-content-list :fetch-data="fetchData"></course-content-list>
  </div>
</template>

<script>
// import CourseContentList from './courseContentList'
import CourseContentList from '@/components/courseContentList'
import { getAllAds, getQueryCourses } from '@/services/course'
export default {
  name: 'CourseContent',
  created () {
    this.loadAds()
  },
  components: {
    CourseContentList
  },
  data () {
    return {
      AdsList: []
    }
  },
  methods: {
    async loadAds () {
      const { data } = await getAllAds({
        spaceKeys: '999'
      })
      if (data.state === 1) {
        this.AdsList = data.content[0].adDTOList
      }
    },
    // 传入子组件的函数
    fetchData (options) {
      return getQueryCourses(options)
    }
  },
  computed: {
    // 广告图状态筛选
    activeAdList () {
      return this.AdsList.filter(item => item.status === 1)
    }
  }
}

</script>
<style lang='scss' scoped>
.my-swipe {
  width: 100%;
}
.my-swipe .van-swipe-item{
  display: flex;
  justify-content: center;
  overflow: hidden;
}
.my-swipe img {
  height: 170px;
}
.course-content-list {
  top: 220px;
  bottom: 50px;
}
</style>
